<!DOCTYPE html>
<html>
<head>
    <?php
        error_reporting(E_ALL);
        session_start();
        require_once("functions/init.php");
        require_once("functions/server-comms.php");
        $action = $_GET["action"];
    ?>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
    <?php
        $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
        if ($browser == true)  {
            echo('<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>');
        } else {
            echo('<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>');
        }
    ?>

    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
        <?php if ($action != "new") {?>
        <script>
            var storyRead = false;
            $('#index').live( 'pageinit',function(event){
                if (!storyRead) {
                    storyRead = true;
                    $.mobile.changePage("story.php", {reloadPage: true});
                }
            });
        </script>
        <?php } ?>
</head>
<body>
    <div data-role="page" id="index" >
        <div data-role="header">
            <h1>Rogue Agent</h1>
        </div><!-- /header -->

        <div data-role="content" id="indexContent">  
            <?php 
            $gameExists = checkForActiveGame(); // talk to server here
            if ($action == "new") {
                // delete current game here
                $gameExists = false;
            }
            if ($gameExists) {
            ?>
                <a href="main.php" class="button" data-role="button">Resume Game</a>    
                <a href="index.php?action=new" class="button" data-role="button">Start New Game</a>
            <?php
            } else {
            ?>
            No active games found. Start a new one!
            <form action="main.php" method="post">
            <table>
                <tr>
                    <td class="colHeader">
                        Players
                    </td>
                    <td class="colValue">
                        <input type="text" name="numAgents" id="numAgents" value="15"/>
                    </td>
                </tr>
                <tr>
                    <td class="colHeader">
                        Variables 
                    </td>
                    <td class="colValue">
                        <input type="text" name="numVars" id="numVars" value="4"/>
                    </td>
                </tr>
                <tr>
                    <td class="colHeader">
                       Talk Radius (m)
                    </td>
                    <td class="colValue">
                        <input type="text" name="talkRadius" id="talkRadius" value="50"/>
                    </td>
                </tr>
            </table>
            <input type="submit" value="Start Game"/>
            </form>
            <?php
            } 
            ?>
        </div><!-- /content -->
    </div>
</body>
</html>
